package com.github.datalineage.data;

import java.util.HashMap;
import java.util.Map;

public class Element {
    private String type;
    private Map<String, Object> attributes=new HashMap<String, Object>();

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getCode() {
        return (String)attributes.get("code");
    }

    public void setCode(String code) {
        attributes.put("code", code);
    }

    public String getName() {
        return (String)attributes.get("name");
    }

    public void setName(String name) {
        attributes.put("name", name);
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

    public String getAttrJSON() {
        StringBuffer sb=new StringBuffer();

        sb.append("{");

        boolean isFirst=true;
        for(Map.Entry<String, Object> item:attributes.entrySet()) {
            if(!isFirst) {
                sb.append(", ");
            } else {
                isFirst=false;
            }
            sb.append(item.getKey()).append(": ");
            if(item.getValue() instanceof String) {
                sb.append("\"").append(item.getValue()).append("\"");
            } else {
                if(item.getValue() instanceof  Number) {
                    sb.append(String.valueOf(item.getValue()));
                }
            }
        }

        sb.append("}");

        return sb.toString();
    }
}
